// 用户质量要求
<template>
  <div class="container">
    <form-content
      :operaList="operaList"
      :tableList="tableList"
      :tableData="tableData"
      :res="res"
      :kind="kind"
      :total_count="total_count"
      @getData="getData"
      @deleteData="deleteData"
      @addData="addData"
      @editData="editData"
    >
      <!-- <template slot="navBar">
        <el-input v-model="search" placeholder="请输入关键字">
          <el-button slot="append" icon="el-icon-search" />
        </el-input>
      </template> -->
    </form-content>
  </div>
</template>

<script>
import { GetQuality } from '@/api/graphiting.js'
import { Delete } from '@/api/reusable.js'
import '@/mock/default.js'
import { tableMix } from '@/mixin/tableMix.js'
import { qualityRequirementOperaList as operaList } from '@/assets/staticData/operaList/graphiting.js'
import { qualityRequirementTableList as tableList } from '@/assets/staticData/tableList/graphiting.js'
export default {
  name: '',
  components: {},
  props: {},
  mixins: [tableMix], // 一些公用的属性方法可以放在mixin里面,各个组件互不影响
  data () {
    return {}
  },
  computed: {},
  watch: {},
  beforeCreate () {},
  created () {
    this.kind = 'qualityRequire'
    this.getData({
      page: 1,
      per_page: 10
    })
  },
  mounted () {
    // this.getData()
  },
  methods: {
    addData (data) {
      this.$axios.get('http://127.0.0.1:7002/addRes')
        .then(res => {
          this.res = res.data
        })
    },
    editData (_id, data) {
      this.$axios.get('http://127.0.0.1:7002/editRes')
        .then(res => {
          // console.log(res)
          this.res = res.data
        })
    },
    getData (data) {
      // console.log('分页', data)
      this.operaList = operaList
      this.tableList = tableList
      // this.$axios.get('http://192.168.132.216:7001/v2/GetQuality?page=1&per_page=10')
      // this.$axios.post('http://192.168.132.216:7001/v2/GetQuality', {
      //   page: 1,
      //   per_page: 10
      // })
      GetQuality(data)
      // this.$axios.get('http://82.156.109.119:7001/v2/GetQuality')
        .then(res => {
          console.log('GetQuality', res)
          if (res.data.data.results === null) {
            this.tableData = []
          } else {
            // 当int类型和float类型传入空值时 会传给后端NaN 再传给前端就是0 通过处理将0转为''
            // 这显然不合理 不过目前只能这样处理 后期一定要改动
            for (let i = 0; i < res.data.data.results.length; i++) {
              for (let j = 0; j < tableList.length; j++) {
                if (res.data.data.results[i][tableList[j].prop] === 0) {
                // console.log(res.data.data.results[i][tableList[j].prop])
                  res.data.data.results[i][tableList[j].prop] = ''
                }
              // console.log(tableList[j].prop)
              }
            }
            this.tableData = res.data.data.results.reverse()
          }
          this.total_count = res.data.data.total_count
        }).catch(err => {
          console.log(err)
        })
    },
    deleteData (data) {
      console.log('我是父组件，我来接收数据', data)
      // this.$axios.get('http://127.0.0.1:7002/delRes')
      Delete({
        _id: data._id,
        collection: 'qualityrequired'
      })
        .then(res => {
          console.log(res)
          this.res = res
          this.getData({
            page: 1,
            per_page: 10
          })
        })
    }
  }
}
</script>

<style scoped lang="">
</style>
